package com.dhcc.DRGsHosp.web.controller.businesslog;

import org.openkoala.businesslog.utils.BusinessLogServletFilter;
import org.openkoala.security.shiro.CurrentUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;

/**
 * User: zjzhai
 * Date: 11/27/13
 * Time: 11:01 AM
 */
public class LogFilter extends BusinessLogServletFilter {
    private static final Logger LOGGER = LoggerFactory.getLogger(LogFilter.class);


    /**
     * 将需要用到的信息放入日志上下文
     *
     * @param req
     * @param resp
     * @param chain
     */
    @Override
    public void beforeFilter(ServletRequest req, ServletResponse resp, FilterChain chain) {
        addIpContext(getIp(req));
        addUrlContext(((HttpServletRequest)req).getServletPath());
        // TODO 需要自己实现获取用户名
        String userCode = CurrentUser.getUserAccount() ;
        addUserContext(userCode);
    }


    public void init(FilterConfig filterConfig) throws ServletException {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    public void destroy() {
        //To change body of implemented methods use File | Settings | File Templates.
    }
}
